package acm.pta15;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

//查找空闲时间
public class 老板的作息表 {
    long now = System.currentTimeMillis();
    static TreeMap<Date, Node> map = new TreeMap<>();
    static DateFormat format = new SimpleDateFormat("HH:mm:ss");

    public static void add(String[] time) {
        try {
            Date start = format.parse(time[0]);
            Date end = format.parse(time[1]);
            map.put(start, new Node(start, end));
        } catch (ParseException ex) {
            throw new RuntimeException(ex);
        }
    }

    public static void sew() {
        try {
            Date curr = format.parse("00:00:00");
            Date end = format.parse("23:59:59");
            while (!curr.equals(end)) {
                Map.Entry<Date, Node> entry = map.ceilingEntry(curr);
                if (entry == null) {
                    System.out.println(format.format(curr) + " - " + format.format(end));
                    break;
                }
                Node node = entry.getValue();
                if (curr.equals(node.start)) {
                    curr = node.end;
                } else {
                    System.out.println(format.format(curr) + " - " + format.format(node.start));
                    curr = node.end;
                }
            }
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            add(sc.nextLine().split("-"));
        }
        sew();
    }

    static class Node {
        Date start;
        Date end;

        Node(Date start, Date end) {
            this.start = start;
            this.end = end;
        }
    }


    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
